/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	VertexSource.h
*
*	Description -	This is a system vertex stream source used for preparing the
*					creation of vertex buffer.
*
*	Comments	-	
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	09/05/2012	-	Creation of this file
**************************************************************************************/
#ifndef _PSX_VERTEX_SOURCE_H_
#define _PSX_VERTEX_SOURCE_H_

#include "PulseSTD.h"
#include "GraphicsTypes.h"
#include "VertexElementSizes.h"
#include "VertexElementTypes.h"

namespace Pulse
{
	class VertexSource
	{
	public:

		VertexSource( void );

		// NOTE: Automatically calls initialize
		VertexSource( EVertexElement::Type type, SIZE_T32 count );

		~VertexSource( void );

		EErrorCode::Type Initialize( EVertexElement::Type type, SIZE_T32 count );
	
		const EVertexElement::Type GetType( void ) const { return m_elementType; }

		const SIZE_T32 GetElementCount( void ) const { return m_elementCount; }

		const SIZE_T32 GetElementSize( void ) const { return m_elementSize; }

		BYTE * GetBuffer( void ) { return m_pBuffer; }

		Vector3 * GetAsPositions( void ) { return m_pPositions; }
		
		const Vector3 * GetAsPositions( void ) const { return m_pPositions; }

		Vector3 * GetAsNormals( void ) { return m_pNormals; }
		
		const Vector3 * GetAsNormals( void ) const { return m_pNormals; }

		Vector3 * GetAsTangents( void ) { return m_pTangents; }
		
		const Vector3 * GetAsTangents( void ) const { return m_pTangents; }

		Vector2 * GetAsTextureDiffuse( void ) { return m_pTextureDiffuse; }
		
		const Vector2 * GetAsTextureDiffuse( void ) const { return m_pTextureDiffuse; }

		//UPOS_T32 VertexSource::AddPosition( Vector3 *pPos )
		//UPOS_T32 VertexSource::AddPositions( SIZE_T32 numElements, Vector3 *pPos )
		//UPOS_T32 VertexSource::AddNormal( Vector3 *pNormal );
		//UPOS_T32 VertexSource::AddNormal( FLOAT x, FLOAT y, FLOAT z );
		//UPOS_T32 VertexSource::AddTextureDiffuse( FLOAT x, FLOAT y )
		//UPOS_T32 VertexSource::AddTextureDiffuse( Vector2 *pUVDiffuse );

	private:

		// Disable methods
		VertexSource( VertexSource & );
		VertexSource & operator = ( VertexSource & );

	private:

		void SetType( EVertexElement::Type type ) { m_elementType = type; }

		BOOL CheckCanAdd( EVertexElement::Type typeToAdd, SIZE_T32 numToAdd = 1 );

		void ClearBuffer( void );

		EErrorCode::Type ResizeBuffer( UINT count );

	private:

		EVertexElement::Type	m_elementType;
		VertexElementSize_T		m_elementSize;
		SIZE_T32				m_elementCount;
		//UPOS_T32				m_writeMarker;

		union
		{
			BYTE	*m_pBuffer;

			Vector3	*m_pPositions;
			Vector3 *m_pNormals;
			Vector3 *m_pTangents;
	
			Vector2 *m_pTextureDiffuse;
		};

	};
}

#endif /* _PSX_VERTEX_SOURCE_H_ */